package com.gitee.feizns.itrip.personal.utils;

import lombok.NonNull;

import java.util.Date;

/**
 * @author feizns
 * @since 2019/1/12 0012
 */
public class DateUtils {

    /**
     * 一天的毫秒数
     */
    public static final long NUMBER_OF_MILLISECONDS_DAY = 1000 * 3600 * 24;

    /**
     * 求日期天数差
     * @param start
     * @param end
     * @return
     */
    public static int diffDay(@NonNull Date start, @NonNull Date end) {
        double result = (Math.abs(start.getTime() - end.getTime()) / NUMBER_OF_MILLISECONDS_DAY);
        return (int) Math.ceil(result);
    }

    /**
     * 添加指定天
     * @param date
     * @param days
     * @return
     */
    public static Date plusDay(@NonNull Date date, int days) {
        return new Date(date.getTime() + (NUMBER_OF_MILLISECONDS_DAY * days));
    }

    /**
     * 添加一天
     * @param date
     * @return
     */
    public static Date plusOneDay(@NonNull Date date) {
        return plusDay(date, 1);
    }

}
